package com.main.printing;

import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.ArrayList;

/**
 * @author Erik Stell
 * @version 1.0
 */
public class PrintingThread extends Thread {

    private final ArrayList list;

    /**
     * @param l
     */
    public PrintingThread(ArrayList l) {
        list = l;
    }

    /**
     *
     */
    public void run() {
        PrinterJob job = PrinterJob.getPrinterJob();
        Book book = new Book();
        // cover page could be appended to book here
        PagePainter fapp = new PagePainter(list);
        PageFormat pf = job.pageDialog(job.defaultPage());
        int count = fapp.calculatePageCount(pf);
        book.append(fapp, pf, count);
        job.setPageable(book);
        if (job.printDialog()) {
            try {
                job.print();
            } catch (PrinterException ex) {
                ex.printStackTrace();
            }
        }
    }
}